<template>
  <div class="scenic-card" @click="handleClick">
    <div class="card-image">
      <a-image
        :src="scenic.coverImage || defaultImage"
        :alt="scenic.scenicName"
        :preview="false"
        fallback=""
      />
    </div>

    <div class="card-content">
      <h3 class="scenic-name" :title="scenic.scenicName">{{ scenic.scenicName }}</h3>

      <!-- 标签移到图片下方 -->
      <div class="tags" v-if="scenic.tags?.length">
        <a-tag v-for="tag in scenic.tags.slice(0, 3)" :key="tag" size="small" color="blue">
          {{ tag }}
        </a-tag>
      </div>

      <div class="card-footer">
        <span class="location" v-if="scenic.scenicLongitude && scenic.scenicLatitude">
          <EnvironmentOutlined />
          {{ scenic.scenicLongitude }}, {{ scenic.scenicLatitude }}
        </span>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { EnvironmentOutlined } from '@ant-design/icons-vue'

interface Props {
  scenic: API.ScenicVO
}

interface Emits {
  (e: 'click', scenic: API.ScenicVO): void
}

const props = defineProps<Props>()
const emit = defineEmits<Emits>()

const defaultImage = 'https://gw.alipayobjects.com/zos/rmsportal/JiqGstEfoWAOHiTxclqi.png'

// 文本截断
const truncateText = (text: string, maxLength: number) => {
  if (!text) return ''
  return text.length > maxLength ? text.slice(0, maxLength) + '...' : text
}

// 处理点击事件
const handleClick = () => {
  emit('click', props.scenic)
}
</script>

<style scoped>
.scenic-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  transition: all 0.3s ease;
  cursor: pointer;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.scenic-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.card-image {
  position: relative;
  height: 180px;
  overflow: hidden;
}

.card-image :deep(.ant-image) {
  width: 100%;
  height: 100%;
}

.card-image :deep(.ant-image img) {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.scenic-card:hover .card-image :deep(.ant-image img) {
  transform: scale(1.05);
}

.card-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(to bottom, transparent 0%, rgba(0, 0, 0, 0.1) 100%);
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 8px;
}

.tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.card-content {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.scenic-name {
  font-size: 16px;
  font-weight: 600;
  color: #262626;
  margin: 0;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenic-brief {
  color: #8c8c8c;
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-clamp: 2;
  overflow: hidden;
  text-align: justify;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
}

.location {
  color: #8c8c8c;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* 移动端适配 */
@media (max-width: 768px) {
  .card-image {
    height: 160px;
  }

  .card-content {
    padding: 12px;
  }

  .scenic-name {
    font-size: 14px;
  }

  .scenic-brief {
    font-size: 12px;
  }
}
</style>
